package com.xie.stack;

/**
 * 编写一个类 Operation 可以返回一个运算符 对应的优先级
 *
 * @author xiezhendong
 * @date 2022/10/17
 */
class Operation {
    private static int ADD = 1;
    private static int SUB = 1;
    private static int MUL = 2;
    private static int DIV = 2;

    /**
     * 写一个方法，返回对应的优先级数字
     *
     * @param operation
     * @return
     */
    public static int getValue(String operation) {
        int result = 0;
        switch (operation) {
            case "+":
                result = ADD;
                break;
            case "-":
                result = SUB;
                break;
            case "*":
                result = MUL;
                break;
            case "/":
                result = DIV;
                break;
            default:
                System.out.println("不存在该运算符" + operation);
                break;
        }
        return result;
    }

    public static boolean isOperator(String token) {
        return ("+".equals(token) || "-".equals(token) ||
                "*".equals(token) || "/".equals(token) ||
                "(".equals(token) || ")".equals(token));
    }

    final static public char Plus = '+';
    final static public char Minus = '-';
    final static public char Mult = '*';
    final static public char Div = '/';
    final static public char LP = '(';
    final static public char RP = ')';

    public static boolean P_NoSmall(char op1, char op2) {
        if (((op1 == Plus || op1 == Minus) && (op2 == Plus || op2 == Minus)) ||  //同为加减
                ((op1 == Mult || op1 == Div) && (op2 == Mult || op2 == Div)) ||      //同为乘除
                ((op1 == Mult || op1 == Div) && (op2 == Plus || op2 == Minus)))     //op1比op2高
        {
            return true;
        } else {
            return false;
        }
    }
}
